﻿using System;
using System.Windows.Forms;

namespace BullshitArticalGenerator
{
    public partial class CShowInformation : Form
    {
        private int _goalTextLength = 0;

        public MainForm ParentForm
        {
            get;
            set;
        }

        public int GoalTextLength
        {
            get
            {
                return _goalTextLength;
            }
            set
            {
                _goalTextLength = value;
                progressBar.Maximum = _goalTextLength + 100;
            }
        }

        private string _formTitle = "显示信息";
        public string FormTitle
        {
            get
            {
                return _formTitle;
            }
            set
            {
                _formTitle = value;
                this.Text = _formTitle;
            }
        }

        private string _showedText = "";
        public string ShowedText
        {
            get
            {
                return _showedText;
            }
            set
            {
                _showedText = value;
                tbItem.Text = _showedText;
                tbItem.SelectionStart = tbItem.Text.Length;
                tbItem.ScrollToCaret();

                lTextLenth.Text = _showedText.Length.ToString() + "字";
                progressBar.Value = _showedText.Length;
                progressBar.Invalidate();
            }
        }

        public CShowInformation()
        {
            InitializeComponent();
        }

        private void CShowInformation_Load(object sender, EventArgs e)
        {
            this.Text = _formTitle;
            tbItem.Text = _showedText;

            // 避免选中全部内容
            tbItem.Select(0, 0);
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        public void ReturnToStart()
        {
            this.TopMost = false;
            MessageBox.Show("成功生成一篇狗屁不通的文章！", "通知", MessageBoxButtons.OK, MessageBoxIcon.Information);

            tbItem.SelectionStart = 0;
            tbItem.ScrollToCaret();

            progressBar.Visible = false;
            lTextLenth.Visible = false;
            btnCopy.Visible = true;
            btnOK.Visible = true;
        }

        private void btnCopy_Click(object sender, EventArgs e)
        {
            Clipboard.SetText(_showedText);
            MessageBox.Show("复制到剪切板成功！", "通知", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        private void CShowInformation_FormClosing(object sender, FormClosingEventArgs e)
        {
            ParentForm.IsGeneratingArticle = false;
            ParentForm.Visible = true;
        }
    }
}
